package com.takeshequ.friends;

import net.tsz.afinal.FinalBitmap;
import android.content.Context;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.takeshequ.R;
import com.takeshequ.chat.ExpressionUtil;

public class ContentItem implements ListItems {

	private Friend friend;
	private String tag;

	public ContentItem(Friend item) {
		friend = item;
	}

	public Friend getFriend() {
		return friend;
	}

	public void setFriend(Friend friend) {
		this.friend = friend;
	}

	public String getTag() {
		return tag;
	}

	public void setTag(String tag) {
		this.tag = tag;
	}

	@Override
	public int getLayout() {
		return R.layout.friends_content_layout;
	}

	@Override
	public boolean isClickable() {
		return true;
	}

	@Override
	public View getView(Context context, View convertView,
			LayoutInflater inflater) {
		convertView = inflater.inflate(getLayout(), null);
		ImageView iv = (ImageView) convertView
				.findViewById(R.id.friends_item_head_img);
		FinalBitmap.create(context).display(iv, friend.getHeadImage());
		TextView tv = (TextView) convertView
				.findViewById(R.id.friends_item_nickName);
		tv.setText(friend.getNickName());

		TextView myCar = (TextView) convertView
				.findViewById(R.id.friends_item_car_name);
		myCar.setText(friend.getCar());

		TextView idiograph = (TextView) convertView
				.findViewById(R.id.friends_item_idiograph);

		SpannableString spannableString = ExpressionUtil.getExpressionString(
				context, friend.getSignature());
		idiograph.setText(spannableString);

		TextView age = (TextView) convertView
				.findViewById(R.id.friends_item_age);
		age.setText(friend.getAge());

		TextView constellation = (TextView) convertView
				.findViewById(R.id.friends_item_constellation);
		constellation.setText(friend.getConstellation());

		ImageView gender = (ImageView) convertView
				.findViewById(R.id.friends_item_gender_img);
		if (friend.getSex().equals("m")) {
			gender.setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.friends_item_male));
		} else {
			gender.setBackgroundDrawable(context.getResources().getDrawable(
					R.drawable.friends_item_female));
		}

		convertView.setTag(this.friend);

		return convertView;
	}
}
